#include<bits/stdc++.h>
using namespace std;
struct ios{
    inline char gc(){
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> inline ios & operator >> (_Tp&x){
        static char ch,sgn; ch = gc(), sgn = 0;
        for(;!isdigit(ch);ch=gc()){if(ch==-1)return *this;sgn|=ch=='-';}
        for(x=0;isdigit(ch);ch=gc())x=x*10+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}io;
#define cin io
const int inf = 0x3f3f3f3f;
int c,b[500011];
int lsh[1000011],idx;
int pl[1000011],m;
typedef struct{
	long long k,b;
}Tree;
Tree t[4000011];
void add(int p,int l,int r,int ll,int rr,long long k,long long b)
{
	if(pl[rr] < l || r < pl[ll]) return;
	if(l <= pl[ll] && pl[rr] <= r)
		return t[p].k += k,t[p].b += b,void();
	int mid = ll + rr >> 1;
	add(p << 1,l,r,ll,mid,k,b);
	add(p << 1 | 1,l,r,mid + 1,rr,k,b);
}
long long ans = 0x3f3f3f3f3f3f3f3f;
vector<int> res;
void DFS(int p,int l,int r)
{
	if(l == r)
	{
		long long w = t[p].k * pl[l] + t[p].b;
		if(w < ans)
			res.clear(),ans = w;
		if(w == ans)
			res.push_back(pl[l]);
		return;
	}
	int mid = l + r >> 1;
	add(p << 1,1,inf,l,mid,t[p].k,t[p].b);
	DFS(p << 1,l,mid);
	add(p << 1 | 1,1,inf,mid + 1,r,t[p].k,t[p].b);
	DFS(p << 1 | 1,mid + 1,r);
}
map<int,int> mp;
vector<int> lst[1000011];
int cnt[1000011];
int usd;
int n;
int k[500011];
vector<int> v[500011];
int main()
{
	freopen("list.in","r",stdin);
	freopen("list.out","w",stdout);
	cin >> n;
	lsh[idx = 1] = 1;
	for(int i = 1;i <= n;i++)
	{
		cin >> k[i];
		for(int j = 1;j <= k[i];j++)
		{
			int x;
			cin >> x;
			v[i].push_back(x);
		}
		for(int j = 1;j < k[i];j++)
		{
			lsh[++idx] = v[i][j] - v[i][j - 1] + 1;
			int p;
			if(!mp[v[i][j]]) p = mp[v[i][j]] = ++usd,lst[p].push_back(1);
			else p = mp[v[i][j]];
			cnt[p]++;
			lst[p].push_back(v[i][j] - v[i][j - 1] + 1);
		}
		{
			int p;
			if(!mp[v[i][0]]) p = mp[v[i][0]] = ++usd,lst[p].push_back(1);
			else p = mp[v[i][0]];
			cnt[p]++;
			lst[p].push_back(inf);
		}
	}
	sort(lsh + 1,lsh + idx + 1);
	for(int i = 1;i <= idx;i++) if(lsh[i] != lsh[i - 1])
		pl[++m] = lsh[i];
	cin >> c;
	for(int i = 1;i <= n;i++)
		cin >> b[i];
	add(1,1,inf,1,m,1ll * c * n,0);
	for(int i = 1;i <= usd;i++)
	{
		sort(lst[i].begin(),lst[i].end());
		int nxt = inf;
		for(int j = lst[i].size() - 1;~j;j--) if(lst[i][j] != nxt)
			add(1,lst[i][j],nxt - 1,1,m,0,1ll * b[cnt[i] - j] * (cnt[i] - j)),nxt = lst[i][j];
	}
	for(int i = 1;i <= idx;i++)
		add(1,1,lsh[i] - 1,1,m,c,0),add(1,lsh[i],inf,1,m,0,c * (lsh[i] - 1ll));
	DFS(1,1,m);
	printf("%lld %d\n",ans,(int)res.size());
	for(auto x:res)
		printf("%d ",x);
	return 0;
}
